<script lang="ts" setup>
import { reactive, onMounted } from 'vue'
import { ElMessage } from 'element-plus'

// do not use same name with ref
let formData = reactive({
    form: {
        jzkz: '',
        kf: '',
        activity_name: '',
    }

})

const onSubmit = () => {
    console.log('submit!')
}

import axios from 'axios'
const getJbss = () => {
    //参考接口文档，请求用户数据
    axios.get("/api/jbss/").then((response) => {
        console.log(response, "网站信息数据")
        //更新用户数据
        formData.form = response.data[0]
        console.log(formData.form, "接收网站信息数据")
    })
}
onMounted(() => {
    getJbss()
})


const updateWzxx = () => {
    console.log(formData.form, "<-----1111修改网站信息数据")
    axios.patch("/api/jbss/1/",
        formData.form,
        { headers: { "Content-Type": "application/json" } }   //
    ).then((response) => {
        console.log(response, "<-----修改网站信息数据")
        // 更新用户数据
        formData.form = response.data
        //console.log(response.data[0], "<------接收网站信息数据")
        // 重新获取数据
        //getWzxx()
        ElMessage({
            type: "success",
            message: "信息保存成功"
        })
    })

}

</script>

<template>
    <el-form :model="formData.form" label-width="auto" style="max-width: 600px">
        <el-form-item label="家族控制">
            <el-select v-model="formData.form.jzkz" prop="jzkz" placeholder="please select your zone">
                <el-option label="开启" value="开启" />
                <el-option label="关闭" value="关闭" />
            </el-select>
        </el-form-item>
        <el-form-item label="客服">
            <el-select v-model="formData.form.kf" prop="kf" placeholder="please select your zone">
                <el-option label="开启" value="开启" />
                <el-option label="关闭" value="关闭" />
            </el-select>
        </el-form-item>
        <el-form-item label="Activity name">
            <el-input v-model="formData.form.activity_name" prop="activity_name" />
        </el-form-item>
        <el-form-item class="but">
            <el-button type="primary" @click="updateWzxx">保存</el-button>
        </el-form-item>
    </el-form>
</template>

<style scoped>
.el-button {
    margin-left: 120px;
}
</style>